/*
 * frxs Inc.  湖南兴盛优选电子商务有限公司.
 * Copyright (c) 2017-2024. All Rights Reserved.
 */
package com.ruoyi;

/**
 * @author Zhi Yang
 * @date 2025年08月30日 16:22
 */
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * spring boot 容器加载后自动监听
 */
@Component
public class StartCommandRunner implements CommandLineRunner {

    @Value("${spring.web.loginurl}")
    private String loginUrl;

    @Value("${spring.auto.openurl}")
    private boolean isOpen;

    @Override
    public void run(String... args) {
        if (isOpen) {
            System.out.println("自动加载指定的页面: " + loginUrl);
            String os = System.getProperties().getProperty("os.name");
            try {
                switch (os){
                    case "Mac OS X":
                        Runtime.getRuntime().exec("open " + loginUrl);
                        break;
                    default:
                        Runtime.getRuntime().exec("cmd /c start " + loginUrl);
                        break;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("浏览器打开页面异常");
            }
        }
    }
}
